package com.sunda.spmsweb.overseacontroller;

import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsoversea.entity.MovementType;
import com.sunda.spmsoversea.service.IMovementTypeService;
import com.sunda.spmsweb.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: spms
 * @description:
 * @author: Wayne Wu
 * @create: 2022-01-14 11:39
 **/
@RestController
@RequestMapping("/movementType")
@Api(tags = "海外仓领用出库移动类型", description = "海外仓领用出库移动类型")
public class MovementTypeController {

    @Autowired
    IMovementTypeService iMovementTypeService;

    @RequestMapping("/getMovementTypeList")
    @ApiOperation(value = "获取领用出库移动类型", notes = "获取领用出库移动类型\n" +
            "", httpMethod = "POST")
    public ResponseResult getMovementTypeList(){
        try {
            return ResponseResult.success().add("movementTypeList", iMovementTypeService.getMovementType());
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/createMovementType")
    @ApiOperation(value = "创建或更新领用出库移动类型", notes = "创建或更新领用出库移动类型\n" +
            "uuid 为空则新增，uuid 不为空则更新，移动类型代码 MOVEMENT_TYPE 具有唯一性，禁止更新；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"uuid\": \"d583581a0bf35961e0530101007f0091\",\n" +
            "\t\"movementType\": \"Z07\",\n" +
            "\t\"movementTypeZhDesc\": \"办公领用\",\n" +
            "\t\"movementTypeEnDesc\": \"Office\",\n" +
            "\t\"applicableBusiness\": \"适用于领用商品在办公中使用\",\n" +
            "\t\"remarks\": \"\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult createMovementType(@RequestBody MovementType movementType){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iMovementTypeService.createMovementType(movementType, userId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/deleteMovementType")
    @ApiOperation(value = "删除领用出库移动类型", notes = "删除领用出库移动类型\n" +
            "根据uuid删除领用出库移动类型", httpMethod = "POST")
    public ResponseResult deleteMovementType(@RequestParam String uuid){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iMovementTypeService.deleteMovementType(uuid, userId);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

}
